import java.util.prefs.Preferences;
import org.rsbot.script.util.WindowUtil;

final class VoluntaryThieve$Configuration
{
  private static final String NODE_PATH_NAME = "/net/vilon/VoluntaryThieve";
  private static final String KEY_ROOT_ALLOW_STORAGE = "/net/vilon/VoluntaryThieve/AllowStorage";
  private static final String KEY_ALLOW_UPDATES = "AllowUpdates";
  private Preferences preferences;
  private boolean hasDeniedOnce;

  private VoluntaryThieve$Configuration(VoluntaryThieve paramVoluntaryThieve)
  {
  }

  private String get(String paramString1, String paramString2)
  {
    if (!initialize()) return paramString2;
    return this.preferences.get(paramString1, paramString2);
  }

  private void put(String paramString1, String paramString2)
  {
    if (!initialize()) return;
    this.preferences.put(paramString1, paramString2);
  }

  private boolean initialize()
  {
    if ((this.preferences == null) && (!confirmStorage())) {
      return false;
    }
    if (this.preferences == null)
      this.preferences = Preferences.userRoot().node("/net/vilon/VoluntaryThieve");
    return true;
  }

  private void removeAll()
  {
    Preferences localPreferences = Preferences.userRoot().node("");
    localPreferences.remove("/net/vilon/VoluntaryThieve/AllowStorage");

    localPreferences = Preferences.userRoot().node("/net/vilon/VoluntaryThieve");
    try {
      localPreferences.removeNode();
    }
    catch (Exception localException) {
    }
    this.preferences = null;
    this.hasDeniedOnce = false;
  }

  private boolean confirmStorage()
  {
    if (this.hasDeniedOnce) return false;

    Preferences localPreferences = Preferences.userRoot().node("");
    if (Boolean.parseBoolean(localPreferences.get("/net/vilon/VoluntaryThieve/AllowStorage", "false"))) {
      return true;
    }
    int i = WindowUtil.showConfirmDialog("Do you give your permission to let the script store configuration data?\nThis is used to save your selected options for later usage.", 1);

    if (i == 0) {
      localPreferences.put("/net/vilon/VoluntaryThieve/AllowStorage", "true");
      return true;
    }

    this.hasDeniedOnce = (i == 1);
    return false;
  }
}